package com.swanclouds.redfish.managers;

import com.google.common.base.Preconditions;
import com.swanclouds.api.managers.EthernetInterfacesService;
import com.swanclouds.core.transport.ClientConstants;
import com.swanclouds.model.common.redfish.CollectionResource;
import com.swanclouds.model.managers.EthernetInterfaces;
import com.swanclouds.model.managers.Oem.BMC.BMCUpdateEthernetInterfaces;
import com.swanclouds.redfish.common.redfish.CollectionResourceModel;
import com.swanclouds.redfish.internal.BaseManagerService;
import com.swanclouds.redfish.managers.domain.EthernetInterfacesModel;
import java.util.ArrayList;
import java.util.List;


public class EthernetInterfacesServiceImpl  extends BaseManagerService implements EthernetInterfacesService {

    /**
     *查询网口集合资源信息
     * @return CollectionResource
     */
    @Override
    public CollectionResource get() {
        return get(CollectionResourceModel.class,uri(ClientConstants.PATH_MANAGERS_ETHERNETINTERFACES,getManagerId())).execute();
    }

    /**
     * 查询指定网口资源信息
     * @param ethernetInterfacesId 必填项 网口资源ID
     * @return  EthernetInterfaces
     */
    @Override
    public EthernetInterfaces getEthernetInterfaces(String ethernetInterfacesId) {
        Preconditions.checkNotNull(ethernetInterfacesId, "ethernetInterfacesId is null");
        return get(EthernetInterfacesModel.class,uri(ClientConstants.PATH_MANAGERS_ETHERNETINTERFACES_ID,getManagerId(),ethernetInterfacesId)).execute();
    }

    /**
     * 查询网口资源详情信息
     * @return java.util.List
     */
    @Override
    public List<EthernetInterfaces> list() {
        List<EthernetInterfaces> ethernetInterfaces = new ArrayList<>();
        CollectionResource resource = get();
        resource.getCollectionResourceList().stream().forEach(ref -> {
            ethernetInterfaces.add(get(EthernetInterfacesModel.class, uri(ref)).execute());
        });
        return ethernetInterfaces;
    }

    /**
     * 设置BMC网口实例的信息
     * @param bmcUpdateEthernetInterfaces 更新以太网接口所需参数
     * @param ethernetInterfacesId 必填项 以太网接口ID
     * @return EthernetInterfaces
     */
    @Override
    public EthernetInterfaces updateEthernetInterfaces(BMCUpdateEthernetInterfaces bmcUpdateEthernetInterfaces,String ethernetInterfacesId) {
        Preconditions.checkNotNull(bmcUpdateEthernetInterfaces, "bmcUpdateEthernetInterfaces is null");
        Preconditions.checkNotNull(ethernetInterfacesId, "ethernetInterfacesId is null");
        getEthernetInterfaces(ethernetInterfacesId);
        return patch(EthernetInterfacesModel.class,uri(ClientConstants.PATH_MANAGERS_ETHERNETINTERFACES_ID,getManagerId(),ethernetInterfacesId))
                .entity(bmcUpdateEthernetInterfaces)
                .execute();
    }
}
